package com.gack.business.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.gack.business.service.MessagePushServiceInterface;
import com.gack.helper.common.AjaxJson;
import com.gack.helper.common.abstractobj.ApiController;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping(ApiController.MESSAGE_PUSH)
public class MessagePushController {
	@Autowired
	private MessagePushServiceInterface messagePushServiceInterface;
	
	@ApiOperation("保存信息推送")
	@PostMapping("/savePush")
	public AjaxJson savePush(String title ,String content,Integer type, String usernames, String createId) {
		AjaxJson ajaxJson = new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(messagePushServiceInterface.addPush(title, content, type, usernames, createId));
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation("根据注册时间筛选人员")
	@PostMapping("/registerTime")
	public AjaxJson registerTime(String startTime, String endTime) {
		AjaxJson ajaxJson = new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(messagePushServiceInterface.registerTime(startTime, endTime));
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败");
		}
		return ajaxJson;
	}

	@ApiOperation("根据未使用线下会议筛选人员")
	@PostMapping("/unusedOfflineMeeting")
	public AjaxJson unusedOfflineMeeting() {
		AjaxJson ajaxJson = new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(messagePushServiceInterface.unusedOfflineMeeting());
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation("根据未使用线上会议筛选人员")
	@PostMapping("/unusedOnlineConference")
	public AjaxJson unusedOnlineConference() {
		AjaxJson ajaxJson = new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(messagePushServiceInterface.unusedOnlineConference());
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation("根据登录次数")
	@PostMapping("/Logins")
	public AjaxJson Logins(String startFrequency, String endFrequency) {
		AjaxJson ajaxJson = new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(messagePushServiceInterface.Logins(startFrequency, endFrequency));
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败");
		}
		return ajaxJson;
	}
	@ApiOperation("上传客户Excel文档")
	@PostMapping("/importCustomersData")
	public AjaxJson importCustomersData(HttpServletRequest request, HttpServletResponse response, MultipartFile dataFile) {
		AjaxJson ajaxJson=new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(messagePushServiceInterface.doImportCustomerData(request, response, dataFile));
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败");
		}
		return ajaxJson;
	}
}
